package billrestauration.controllers;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import billrestaurant.extra.upload.FilesUpload;

@Controller
public class TestController {
	@Value("${testmultiupload.dir}")
	String dir;
	@Autowired  
	billrestaurant.extra.upload.FilesValidator fileValidator;  
	  
	@RequestMapping(value="/testmultiupload",method=RequestMethod.GET)
public String testmultiupload(Model model,@ModelAttribute("testmultiupload") FilesUpload testmultiupload,
		 BindingResult result){
	return "testmultiupload";
}
	@RequestMapping(value="/testmultiupload",method=RequestMethod.POST)
	public String testmultiuploaddo(Model model,@ModelAttribute("testmultiupload") FilesUpload testmultiupload,
			 BindingResult result){
		try {
			fileValidator.validate(testmultiupload, result);  
			  if (result.hasErrors()) {  
				 return testmultiupload(model,testmultiupload,  result);
				  }  
			String res[]=testmultiupload.moves(dir);
			model.addAttribute("filesname",res);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			model.addAttribute("error", e.getMessage());
		}
		return "testmultiupload";
	}
}
